#include <windows.h>
#include <gl\gl.h>
#include <gl\glu.h>
#define _USE_MATH_DEFINES
#include <math.h>
#include "funcs.h"

extern float ratio;
extern char drawSubtype;

void DrawTask12(){
	GLfloat triangle1[3][3] = { {.0f, 0.3f, 0.2f}, {0.3f, 0.3f, .0f}, {.0f, .0f, 0.7f} };
	GLfloat triangle1Color[3] = { 1.0f, 0.0f, 0.0f };
	GLfloat square[4][3] = { {-0.5f, 0.5f, 0.3f}, {-0.5f, -0.5f, 0.3f}, {0.5f, -0.5f, 0.3f}, {0.5f, 0.5f, 0.3f} };
	GLfloat squareColor[3] = { 0.0f, 1.0f, 0.0f };
	GLfloat triangle2[3][3] = { {.0f, .0f, 0.3f}, {0.4f, .0f, 0.5f}, {-0.5f, 0.5f, -1.0f} };
	GLfloat triangle2Color[3] = { 0.0f, 0.0f, 1.0f };

	switch(drawSubtype){
	case 1:
		glDisable(GL_DEPTH_TEST);
		break;
	case 2:
		glEnable(GL_DEPTH_TEST);
		break;
	}
	glEnableClientState(GL_VERTEX_ARRAY);
	glMatrixMode(GL_PROJECTION);
	glLoadIdentity();
	glMatrixMode(GL_MODELVIEW);
	glLoadIdentity();
	glPushMatrix();

	glScalef(ratio, 1.0f, 1.0f);
	glVertexPointer(3, GL_FLOAT, 0, triangle1);
	glColor3fv(triangle1Color);
	glDrawArrays(GL_TRIANGLES, 0, 3);
	glVertexPointer(3, GL_FLOAT, 0, square);
	glColor3fv(squareColor);
	glDrawArrays(GL_QUADS, 0, 4);
	glVertexPointer(3, GL_FLOAT, 0, triangle2);
	glColor3fv(triangle2Color);
	glDrawArrays(GL_TRIANGLES, 0, 3);
	glDisableClientState(GL_VERTEX_ARRAY);

	glPopMatrix();
	glEnable(GL_DEPTH_TEST);
}

void DrawTask34(){
	GLfloat side[24][3] = {	{-1.0, -1.0, 1.0, }, 	{1.0, -1.0, 1.0}, {1.0, 1.0, 1.0}, {-1.0, 1.0, 1.0}, 		// the close one
							{-1.0, -1.0, -1.0, }, {1.0, -1.0, -1.0}, {1.0, 1.0, -1.0}, {-1.0, 1.0, -1.0}, 	// the far one
							{-1.0, 1.0, 1.0, }, {1.0, 1.0, 1.0}, {1.0, 1.0, -1.0}, {-1.0, 1.0, -1.0}, 
							{-1.0, -1.0, 1.0, }, {1.0, -1.0, 1.0}, {1.0, -1.0, -1.0}, {-1.0, -1.0, -1.0}, 
							{-1.0, -1.0, 1.0, }, {-1.0, -1.0, -1.0}, {-1.0, 1.0, -1.0}, {-1.0, 1.0, 1.0}, 
							{1.0, -1.0, 1.0, }, {1.0, -1.0, -1.0}, {1.0, 1.0, -1.0}, {1.0, 1.0, 1.0} };
	glMatrixMode(GL_PROJECTION);
	glLoadIdentity();
	switch(drawSubtype){
	case 1:
		glOrtho(-1.0, 1.0, -1.0, 1.0, 3.0, 10.0);
		break;
	case 2:
		glFrustum(-1.0, 1.0, -1.0, 1.0, 3.0, 10.0);
		break;
	}
	
	glMatrixMode(GL_MODELVIEW);
	glEnableClientState(GL_VERTEX_ARRAY);
	glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);
	glPushMatrix();
	
	glTranslatef(0.0f, 0.0f, -5.0f);
	glScalef(ratio, 1.0f, 1.0f);
	glVertexPointer(3, GL_FLOAT, 0, side);
	glDrawArrays(GL_QUADS, 0, 24);

	glPopMatrix();
	glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
	glDisableClientState(GL_VERTEX_ARRAY);
}

void DrawTask56(){	
	GLfloat side[24][3] = {	{-1.0, -1.0, 1.0, }, 	{1.0, -1.0, 1.0}, {1.0, 1.0, 1.0}, {-1.0, 1.0, 1.0}, 		// the close one
							{-1.0, -1.0, -1.0, }, {1.0, -1.0, -1.0}, {1.0, 1.0, -1.0}, {-1.0, 1.0, -1.0}, 	// the far one
							{-1.0, 1.0, 1.0, }, {1.0, 1.0, 1.0}, {1.0, 1.0, -1.0}, {-1.0, 1.0, -1.0}, 
							{-1.0, -1.0, 1.0, }, {1.0, -1.0, 1.0}, {1.0, -1.0, -1.0}, {-1.0, -1.0, -1.0}, 
							{-1.0, -1.0, 1.0, }, {-1.0, -1.0, -1.0}, {-1.0, 1.0, -1.0}, {-1.0, 1.0, 1.0}, 
							{1.0, -1.0, 1.0, }, {1.0, -1.0, -1.0}, {1.0, 1.0, -1.0}, {1.0, 1.0, 1.0} };
	GLfloat sideColor[6][3] = { {0.5f, 0.0f, 0.0f} , {0.0f, 0.5f, 0.0f},
								{0.0f, 0.0f, 0.5f}, {0.9f, 0.5f, 0.0f},
								{0.0f, 0.9f, 0.5f}, {0.5f, 0.0, 0.9f} };

	glMatrixMode(GL_PROJECTION);
	glLoadIdentity();
	glFrustum(-1.0, 1.0, -1.0, 1.0, 2.0, 7.0);
	switch(drawSubtype){
	case 1:
		glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);
		break;
	case 2:
		glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
		break;
	}	
	glMatrixMode(GL_MODELVIEW);
	glEnableClientState(GL_VERTEX_ARRAY);	
	glPushMatrix();
	
	glTranslatef(0.0f, 0.0f, -5.0f);
	glScalef(ratio, 1.0f, 1.0f);
	glRotatef(30, 1, 0, 0);
	glRotatef(70, 0, 1, 0);
	glVertexPointer(3, GL_FLOAT, 0, side);
	for(int i = 0; i<6; i++){
		glColor3fv(sideColor[i]);
		glDrawArrays(GL_QUADS, i*4, 4);
	}

	glPopMatrix();
	glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
	glDisableClientState(GL_VERTEX_ARRAY);
}